#include "Result.h"



void Result(HYPRE_IJVector x){
    double *values = malloc(nrows*sizeof(double));
    HYPRE_IJVectorGetValues(x, nrows, rows, values);

    if(myrank == 0){
        gather_x = (double *)malloc(Matrix_size*sizeof(double));
        counts   = (int *)malloc(sum_rank*sizeof(int));
        disp     = (int *)malloc(sum_rank*sizeof(int));
        for(i = 0; i < sum_rank-1; i++){
            counts[i] = rows_average;
            disp[i]   = i*rows_average;
            }
        counts[sum_rank-1] = Matrix_size%sum_rank+rows_average;
        disp[sum_rank-1]   = (sum_rank-1)*rows_average;
        }

    MPI_Barrier(MPI_COMM_WORLD);
    MPI_Gatherv(values, nrows, MPI_DOUBLE, gather_x, counts, disp, MPI_DOUBLE, 0, MPI_COMM_WORLD);
    if(myrank == 0){
        sprintf(filename, "./result/x_%d",Matrix_size);
        PlotFile = fopen(filename, "w");
        for(i = 0; i < Matrix_size; i++){
            fprintf(PlotFile, "\t%f\n", gather_x[i]);
            }
        fclose(PlotFile);
        }
    free(gather_x);
    free(values);
    free(counts);
    free(disp);
    }
